﻿using System;
using System.Collections.Generic;
using System.Text;
using CoderJoe.WoW.GearManager.Views;
using CoderJoe.WoW.Services;
using System.Drawing;
using System.Windows.Forms;

namespace CoderJoe.WoW.GearManager
{
    public class ItemToolTipController
        : Controller
    {

        public ItemToolTipController(Workspace workspace)
            : base(workspace)
        {
        }

        public void Show(int itemId, Control control, Point location)
        {
            ItemService itemService = Workspace.Resolve<ItemService>();
            ItemDetail item = itemService.FindOrLoadItemDetail(itemId);
            ItemToolTipModel model = new ItemToolTipModel();
            model.Load(item);

            using (ItemToolTip toolTip = new ItemToolTip(this, model))
            {
                //model.NameColor = GetNameColor(item.QualityId);

                //ContextMenuStrip strip = new ContextMenuStrip();

                ////Label l = new Label();
                ////l.Text = model.Name;
                ////l.ForeColor = model.NameColor;

                ////strip.Items.Add("Testing");
                ////strip.Items.Add(new ToolStripControlHost(l));
                ////strip.AutoSize = true;
                //strip.ShowCheckMargin = false;
                //strip.ShowImageMargin = false;
                //strip.ShowItemToolTips = false;
                //strip.LayoutStyle = ToolStripLayoutStyle.Flow;

                //strip.AutoSize = false;
                //strip.Size = Size.Add(toolTip.Size, new Size(20, 20));
                //strip.BackColor = Color.Black;
                //strip.can
                

                ////strip.PreferredSize = toolTip.Size;

                //ToolStripControlHost host = new ToolStripControlHost(toolTip);
                //host.AutoSize = false;
                //host.Size = toolTip.GetPreferredSize(toolTip.Size);
                //strip.Items.Add(host);

                control.MouseLeave += new EventHandler(delegate(object sender, EventArgs args)
                    {
                        toolTip.Hide();
                        toolTip.Dispose();
                    });
                //strip.Show(location);

                toolTip.Location = location;
                toolTip.Show();
            }
        }

        private Color GetNameColor(int quality)
        {
            switch ((ItemQuality)quality)
            {
                case ItemQuality.Poor:
                    return Color.FromArgb(0x009D9D9D); // Gray
                case ItemQuality.Common:
                    return Color.FromArgb(0x00FFFFFF); // White
                case ItemQuality.Uncommon:
                    return Color.FromArgb(0x001EFF00); // Green
                case ItemQuality.Rare:
                    return Color.FromArgb(0x000070DD); // Blue
                case ItemQuality.Epic:
                    return Color.FromArgb(0x00A335EE); // Purple
                case ItemQuality.Legendary:
                    return Color.FromArgb(0x00FF8000); // Orange
                case ItemQuality.Artifact:
                    return Color.FromArgb(0x00E5CC80); // Red
            }

            return Color.White;
        }
    }
}
